<?php

namespace app\rental\validate;

use app\admin\model\RouteModel;
use think\Validate;

class RentalCarValidate extends Validate
{
    protected $rule = [
        'title'  => 'require',
        'category_id'  => 'require',
        'brand_id'  => 'require',
        'rank_id'  => 'require',
        'primary'  => 'checkPrimary',
        'bodywork'  => 'checkBodywork',
        'engine'  => 'checkEngine',
        'drive'  => 'checkDrive',

    ];
    protected $message = [
        'title.require' => '标题不能为空',
        'category_id.require' => '请选择分类',
        'brand_id.require' => '请选择品牌',
        'rank_id.require' => '请选择级别',
    ];

    // 自定义验证规则
    protected function checkPrimary($value)
    {
        if (empty($value['price'])) {
           return "请输入价格!";
        }
        if (empty($value['type'])) {
           return "请输入类型!";
        }
        if (empty($value['exterior'])) {
           return "请输入外观!";
        }
        if (empty($value['interior'])) {
           return "请输入内饰!";
        }
        return true;
    }
    protected function checkBodywork($value)
    {
        if(empty($value['length'])&&empty($value['width'])&&empty($value['height'])&&empty($value['structure'])&&empty($value['wheel_base'])){
            return "请输入车身属性!";
        }
        if (empty($value['length'])) {
           return "请输入车身长度!";
        }
        if (empty($value['width'])) {
           return "请输入车身宽度!";
        }
        if (empty($value['height'])) {
           return "请输入车身高度!";
        }
        if (empty($value['structure'])) {
           return "请输入车身结构!";
        }
        if (empty($value['wheel_base'])) {
           return "请输入车身轴距!";
        }
        return true;
    }
    protected function checkEngine($value)
    {
        if(empty($value['type'])&&empty($value['max_torque'])&&empty($value['max_horsepower'])&&empty($value['fuel'])){
            return "请输入发动机属性!";
        }
        if (empty($value['type'])) {
           return "请输入发动机型号!";
        }
        if (empty($value['max_torque'])) {
           return "请输入发动机最大扭矩!";
        }
        if (empty($value['max_horsepower'])) {
           return "请输入发动机最大马力!";
        }
        if (empty($value['fuel'])) {
           return "请输入发动机燃料类型!";
        }
        return true;
    }
    protected function checkDrive($value)
    {
        if(empty($value['gearbox'])&&empty($value['type'])){
            return "请输入驱动属性!";
        }
        if (empty($value['type'])) {
           return "请输入驱动方式!";
        }
        if (empty($value['gearbox'])) {
           return "请输入变速箱属性!";
        }
        return true;
    }
    protected function checkUnderpan($value)
    {
        if(empty($value['front_suspension'])&&empty($value['rear_suspension']) &&empty($value['structure'])){
            return "请输入底盘属性!";
        }
        if (empty($value['front_suspension'])) {
           return "请输入前悬架类型!";
        }
        if (empty($value['rear_suspension'])) {
           return "请输入后悬架类型!";
        }
        if (empty($value['structure'])) {
           return "请输入车体结构!";
        }
        return true;
    }
}
